package com.huaxia.controller.realAct;

import com.huaxia.pojo.realAct.*;
import com.huaxia.service.realAct.RealActService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.WebApplicationContext;

import javax.servlet.ServletContext;
import java.util.List;

/**
 * @author wangli 爱我华夏，爱我中华！
 * @date 2020/06/08 16:47
 */
@RestController
@RequestMapping("/realAct")
public class RealActController {


    @Autowired
    private WebApplicationContext webApplicationContext;
    @Autowired
    private RealActService realActService;

    @GetMapping("/getBranchThisMonthAct")
    public List<BranchMonthAct> getBranchThisMonthAct(){
        ServletContext servletContext = webApplicationContext.getServletContext();
        List<BranchMonthAct> branchMonthActs = (List<BranchMonthAct>) servletContext.getAttribute("branchThisMonthActs");
        if(branchMonthActs==null){
            branchMonthActs = realActService.getBranchThisMonthAct();
            servletContext.setAttribute("branchThisMonthActs",branchMonthActs);
            return branchMonthActs;
        }
        return branchMonthActs;
    }

    @GetMapping("/getBranchNextMonthAct")
    public List<BranchMonthAct> getBranchNextMonthAct(){
        ServletContext servletContext = webApplicationContext.getServletContext();
        List<BranchMonthAct> branchMonthActs = (List<BranchMonthAct>) servletContext.getAttribute("branchNextMonthActs");
        if(branchMonthActs==null){
            branchMonthActs = realActService.getBranchNextMonthAct();
            servletContext.setAttribute("branchNextMonthActs",branchMonthActs);
            return branchMonthActs;
        }
        return branchMonthActs;
    }

    @GetMapping("/getSaleDeptMonthAct")
    public List<SaleDeptMonthAct> getSaleDeptMonthAct(){
        ServletContext servletContext = webApplicationContext.getServletContext();
        List<SaleDeptMonthAct> saleDeptMonthActs = (List<SaleDeptMonthAct>) servletContext.getAttribute("saleDeptMonthActs");
        if(saleDeptMonthActs==null){
            saleDeptMonthActs = realActService.getSaleDeptMonthAct();
            servletContext.setAttribute("saleDeptMonthActs",saleDeptMonthActs);
            return saleDeptMonthActs;
        }
        return saleDeptMonthActs;
    }

    @GetMapping("/getBranchClassAct")
    public List<BranchClassAct> getBranchClassAct(){
        ServletContext servletContext = webApplicationContext.getServletContext();
        List<BranchClassAct> branchClassActs = (List<BranchClassAct>) servletContext.getAttribute("branchClassActs");
        if(branchClassActs==null){
            branchClassActs = realActService.getBranchClassAct();
            servletContext.setAttribute("branchClassActs",branchClassActs);
            return branchClassActs;
        }
        return branchClassActs;
    }

    @GetMapping("/getSaleDeptClassAct")
    public List<SaleDeptClassAct> getSaleDeptClassAct(){
        ServletContext servletContext = webApplicationContext.getServletContext();
        List<SaleDeptClassAct> saleDeptClassActs = (List<SaleDeptClassAct>) servletContext.getAttribute("saleDeptClassActs");
        if(saleDeptClassActs==null){
            saleDeptClassActs = realActService.getSaleDeptClassAct();
            servletContext.setAttribute("saleDeptClassActs",saleDeptClassActs);
            return saleDeptClassActs;
        }
        return saleDeptClassActs;
    }

    @GetMapping("/getBranchBcAct")
    public List<BranchBcAct> getBranchBcAct(){
        ServletContext servletContext = webApplicationContext.getServletContext();
        List<BranchBcAct> branchBcActs = (List<BranchBcAct>) servletContext.getAttribute("branchBcActs");
        if(branchBcActs==null){
            branchBcActs = realActService.getBranchBcAct();
            servletContext.setAttribute("branchBcActs",branchBcActs);
            return branchBcActs;
        }
        return branchBcActs;
    }

    @GetMapping("/getSaleDeptBcAct")
    public List<SaleDeptBcAct> getSaleDeptBcAct(){
        ServletContext servletContext = webApplicationContext.getServletContext();
        List<SaleDeptBcAct> saleDeptBcActs = (List<SaleDeptBcAct>) servletContext.getAttribute("saleDeptBcActs");
        if(saleDeptBcActs==null){
            saleDeptBcActs = realActService.getSaleDeptBcAct();
            servletContext.setAttribute("saleDeptBcActs",saleDeptBcActs);
            return saleDeptBcActs;
        }
        return saleDeptBcActs;
    }

    @GetMapping("/getBranchBmAct")
    public List<BranchBmAct> getBranchBmAct(){
        ServletContext servletContext = webApplicationContext.getServletContext();
        List<BranchBmAct> branchBmActs = (List<BranchBmAct>) servletContext.getAttribute("branchBmActs");
        if(branchBmActs==null){
            branchBmActs = realActService.getBranchBmAct();
            servletContext.setAttribute("branchBmActs",branchBmActs);
            return branchBmActs;
        }
        return branchBmActs;
    }

    @GetMapping("/getSaleDeptBmAct")
    public List<SaleDeptBmAct> getSaleDeptBmAct(){
        ServletContext servletContext = webApplicationContext.getServletContext();
        List<SaleDeptBmAct> saleDeptBmActs = (List<SaleDeptBmAct>) servletContext.getAttribute("saleDeptBmActs");
        if(saleDeptBmActs==null){
            saleDeptBmActs = realActService.getSaleDeptBmAct();
            servletContext.setAttribute("saleDeptBmActs",saleDeptBmActs);
            return saleDeptBmActs;
        }
        return saleDeptBmActs;
    }

    @GetMapping("/getSzMonthAct")
    public List<SzMonthAct> getSzMonthAct(){
        ServletContext servletContext = webApplicationContext.getServletContext();
        List<SzMonthAct> szMonthActs = (List<SzMonthAct>) servletContext.getAttribute("szMonthActs");
        if(szMonthActs==null){
            szMonthActs = realActService.getSzMonthAct();
            servletContext.setAttribute("szMonthActs",szMonthActs);
            return szMonthActs;
        }
        return szMonthActs;
    }
}
